﻿package little.bunny;

//import tl.updateInterface.DoUpdate;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import little.bunny.R;

public class XiaoBaiTuActivity extends Activity {
	private int[] btids = {R.id.button1,R.id.button2,R.id.button3,R.id.button4,R.id.button5,R.id.button6,R.id.btn_huiyuan,R.id.btn_tousu,R.id.btn_viewtrace};
    private Button[] bt = new Button[btids.length]; 
    private ImageView logoImageView;
    private Button backButton;
    
    //DoUpdate du=new DoUpdate(this, "http://www.littlebunny.com.cn/apkupdate/", "ver.json");
	/** Called when the activity is first created. */
        
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //检查更新
        checkUpdate("http://www.littlebunny.com.cn/apkupdate/","ver.json");
        //du.updateCheckInStart();
        
        //退出按钮
        backButton=(Button)findViewById(R.id.back_button);
		backButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
        
        logoImageView=(ImageView)findViewById(R.id.logo_imageView);
        //光标定位
        logoImageView.setFocusable(true);
        logoImageView.setFocusableInTouchMode(true);
        searchBtAndListener();
    }
    
    public boolean checkUpdate(String UpdateUrl, String v_json) {
		Updater updater = new Updater(UpdateUrl, v_json, this);
		try
		{
			if (updater.needUpdate())//found update
			{
				updater.showNewVersionUpdate();
			}
		}
		catch (Exception e) {
			return false;
		}
		return true;
	}
    
    //获取按钮，添加事件
    private void searchBtAndListener(){
    	for (int i = 0; i < btids.length; i++) {
			bt[i]=(Button)findViewById(btids[i]);
			bt[i].setOnClickListener(new btOnChilkListener());
		}
    }
    
    //事件监听器 
    private class btOnChilkListener implements OnClickListener{

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent myIntent=new Intent();
			//最新资讯
			if(v==bt[0]){
				///ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/news.asp");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\">");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 2);
				myIntent.putExtra("bj", 0);
				startActivity(myIntent);
			}
			//服务网点
			if(v==bt[1]){
				//ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/Products.asp");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\".*?>");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 3);
				myIntent.putExtra("bj", 1);
				startActivity(myIntent);
			}
			//洗涤价格
			if(v==bt[2]){
				//ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/jiamu.asp?id=1");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\">");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 2);
				myIntent.putExtra("bj", 2);
				startActivity(myIntent);
			}
			//公司介绍
			if(v==bt[3]){
				//ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiListActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/About.asp?id=1");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\">");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 2);
				myIntent.putExtra("title", "公司介绍");
				startActivity(myIntent);
			}
			//加盟我们
			if(v==bt[4]){
				//ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiListActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/jiameng.asp?id=1");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\">");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 2);
				myIntent.putExtra("title", "加盟我们");
				startActivity(myIntent);
			}
			//服务项目
			if(v==bt[5]){
				//ArrayList<SortS> myListSorts=getSortList(,,, 1, ,1);
				myIntent.setClass(XiaoBaiTuActivity.this, NeiListActivity.class);
				myIntent.putExtra("url", "http://www.littlebunny.com.cn/xm.asp?id=1");
				myIntent.putExtra("moban", "<li><a href=\"&need;\" title=\"&need;\">");
				myIntent.putExtra("start", "<div id=\"left\"><ul>");
				myIntent.putExtra("startid", 1);
				myIntent.putExtra("end", "<div class=\"kong\"></div>");
				myIntent.putExtra("endid", 2);
				myIntent.putExtra("title", "服务项目");
				startActivity(myIntent);
			}
			
			//我的小白兔
			if (v==bt[6])
			{
				myIntent.setClass(XiaoBaiTuActivity.this, MyLogin.class);
				startActivity(myIntent);
			}
			//投诉
			if (v==bt[7])
			{
				myIntent.setClass(XiaoBaiTuActivity.this, CustomTousu.class);
				startActivity(myIntent);
			}
			//衣物跟踪
			if (v==bt[8])
			{
				myIntent.setClass(XiaoBaiTuActivity.this, CustClothesTrace.class);
				startActivity(myIntent);
			}
			
		}
    	
    }
    
    /**
	 * 退出设置，这是个好习惯~
	 */
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new AlertDialog.Builder(this)
					.setMessage("是否退出?")
					.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									//退出时候，结束通知栏信息和操作
									System.exit(0);
								}
							})
					.setNegativeButton("取消",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							}).show();
		}
		return true;
	}
    
    
    
	@Override 
    
	public void onConfigurationChanged(Configuration newConfig) { 
		                super.onConfigurationChanged(newConfig); 
		                if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { 
			                        // land do nothing is ok 
			                } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { 
				                        // port do nothing is ok 
				                } 
		        } 
   
    
}